package com.bcmusic.point.controller;

import com.bcmusic.point.pojo.UserLoginLog;
import com.bcmusic.point.service.UserLoginLogService;
import com.github.pagehelper.PageInfo;
import entity.Result;
import entity.StatusCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/****
 * @Author:admin
 * @Description:
 * @Date 2019/6/14 0:18
 *****/

@RestController
@RequestMapping("/userLoginLog")
@CrossOrigin
public class UserLoginLogController {

    @Autowired
    private UserLoginLogService userLoginLogService;

    /***
     * UserLoginLog分页条件搜索实现
     * @param userLoginLog
     * @param page
     * @param size
     * @return
     */
    @PostMapping(value = "/search/{page}/{size}" )
    public Result<PageInfo> findPage(@RequestBody(required = false)  UserLoginLog userLoginLog, @PathVariable  int page, @PathVariable  int size){
        //调用UserLoginLogService实现分页条件查询UserLoginLog
        PageInfo<UserLoginLog> pageInfo = userLoginLogService.findPage(userLoginLog, page, size);
        return new Result(true,StatusCode.OK,"查询成功",pageInfo);
    }

    /***
     * UserLoginLog分页搜索实现
     * @param page:当前页
     * @param size:每页显示多少条
     * @return
     */
    @GetMapping(value = "/search/{page}/{size}" )
    public Result<PageInfo> findPage(@PathVariable  int page, @PathVariable  int size){
        //调用UserLoginLogService实现分页查询UserLoginLog
        PageInfo<UserLoginLog> pageInfo = userLoginLogService.findPage(page, size);
        return new Result<PageInfo>(true,StatusCode.OK,"查询成功",pageInfo);
    }

    /***
     * 多条件搜索品牌数据
     * @param userLoginLog
     * @return
     */
    @PostMapping(value = "/search" )
    public Result<List<UserLoginLog>> findList(@RequestBody(required = false)  UserLoginLog userLoginLog){
        //调用UserLoginLogService实现条件查询UserLoginLog
        List<UserLoginLog> list = userLoginLogService.findList(userLoginLog);
        return new Result<List<UserLoginLog>>(true,StatusCode.OK,"查询成功",list);
    }

    /***
     * 根据ID删除品牌数据
     * @param id
     * @return
     */
    @DeleteMapping(value = "/{id}" )
    public Result delete(@PathVariable Long id){
        //调用UserLoginLogService实现根据主键删除
        userLoginLogService.delete(id);
        return new Result(true,StatusCode.OK,"删除成功");
    }

    /***
     * 修改UserLoginLog数据
     * @param userLoginLog
     * @param id
     * @return
     */
    @PutMapping(value="/{id}")
    public Result update(@RequestBody  UserLoginLog userLoginLog,@PathVariable Long id){
        //设置主键值
        userLoginLog.setLoginLogId(id);
        //调用UserLoginLogService实现修改UserLoginLog
        userLoginLogService.update(userLoginLog);
        return new Result(true,StatusCode.OK,"修改成功");
    }

    /***
     * 新增UserLoginLog数据
     * @param userLoginLog
     * @return
     */
    @PostMapping
    public Result add(@RequestBody   UserLoginLog userLoginLog){
        //调用UserLoginLogService实现添加UserLoginLog
        userLoginLogService.add(userLoginLog);
        return new Result(true,StatusCode.OK,"添加成功");
    }

    /***
     * 根据ID查询UserLoginLog数据
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Result<UserLoginLog> findById(@PathVariable Long id){
        //调用UserLoginLogService实现根据主键查询UserLoginLog
        UserLoginLog userLoginLog = userLoginLogService.findById(id);
        return new Result<UserLoginLog>(true,StatusCode.OK,"查询成功",userLoginLog);
    }

    /***
     * 查询UserLoginLog全部数据
     * @return
     */
    @GetMapping
    public Result<List<UserLoginLog>> findAll(){
        //调用UserLoginLogService实现查询所有UserLoginLog
        List<UserLoginLog> list = userLoginLogService.findAll();
        return new Result<List<UserLoginLog>>(true, StatusCode.OK,"查询成功",list) ;
    }
}
